#ifndef _GAMEPLAYERCLIENT_H
#define _GAMEPLAYERCLIENT_H

#pragma once
#include "net\Winsock2ClientSocket.h"
#include "net\Winsock2SocketFactory.h"
#include "concurrent\CriticalSection.h"
#include "GameEvent.h"
#include "ByteBuffer.h"
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
#include <fstream>

using namespace std;
using namespace net;
using namespace concurrent;

class GamePlayerClient
{
public:
	GamePlayerClient(string);
	GamePlayerClient(string, string);
	GamePlayerClient(string, string, string);
    virtual ~GamePlayerClient(void);
	int connectToServer(void);
	bool isConnected(void);
	void beginSession(void);
	void endSession(void);
    int startReceivingUpdates(void);
	int startSendingUpdates(void);
	void stopReceivingUpdates(void);
	void stopSendingUpdates(void);
	int disconnectFromServer(void);
	string getName(void);
	string getBackgroundFile(void);
	void setBackgroundFile(string path);
	bool isInitialized(void);
	void sendUpdate(GameEvent*);
	bool hasUpdates(void);
	bool connectionError();
	GameEvent* recieveUpdates(void);
	CriticalSection* getEventInputQueueLock(void);
	void setEventInputQueueLock(CriticalSection* eventInputQueueLock);
	queue<GameEvent*>* getEventInputQueue(void);
	ByteBuffer* getSceneBuff();
	void receiveSceneState(void);
	void setEventInputQueue(queue<GameEvent*>* eventInputQueue);
private:
	void receiveGameFiles(void);
	void getInfo(struct addrinfo*);
	string name;
	ByteBuffer* sceneBuff;
	ClientSocket* socket;
	string serverHost;
	string serverPort;
	bool _isConnected;
	bool isReceive;
	bool isSend;
	bool connectError;
	bool _isInitialized;
	bool _isSceneInitialized;
	string backgroundFile;
	queue<GameEvent*> eventOutputQueue;
	CriticalSection* eventOutputQueueLock;
	queue<GameEvent*>* eventInputQueue;
	CriticalSection* eventInputQueueLock;
	static string DEFAULT_SERVER_HOST;
	static string DEFAULT_SERVER_PORT;
};

#endif
